#include <limits.h>  // INT_MIN,INT_MAX
#include <math.h>    // abs,pow

#include <algorithm>      // sort
#include <iostream>       // cout,cin
#include <numeric>        // partial_sum
#include <string>         // string
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <vector>         // vector

using namespace std;

// 如果x是2的幂则返回True，否则返回False
bool IsPowerOf2(int x) { return (x & (x - 1)) == 0; }

class Solution {
   public:
    int findMaxLength(vector<int>& nums) {
        int size = nums.size();

        unordered_map<int, int> count;
        count[0] = -1;

        int now = 0;  // 1比0多的数量
        int ans = 0;
        for (int i = 0; i < size; i++) {
            if (nums[i] == 1) {
                now++;
            } else {
                now--;
            }
            if (count.count(now) != 0) {
                ans = max(ans, i - count[now]);
            } else {
                count[now] = i;
            }
        }
        return ans;
    }
};

int main() {
    Solution solution;
    return 0;
}